package test0ne;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.*;

import static test0ne.DateUtil.getCurTimeMillis;

public class testString {

    public static final float lilv = (float) 1.04;
    public static void main(String[] args) {
//        float ben =  tsetOne();
//        String mobile = "02985807040";
//        System.out.println(mobile.matches("^[0-9]*$"));
//        System.out.println(ben*Math.pow(lilv, 28));

        List<Short> set1 = new ArrayList<>();
        set1.add((short) 1);
        set1.add((short) 2);
        set1.add((short) 3);

        List<Integer> set2 = new ArrayList<>();
        set2.add(3);
        set2.add(4);
        set2.add(5);

//        System.out.println(set1.retainAll(set2));

        for (Short aShort : set1) {
            for (Integer integer : set2) {
                if((int)aShort == integer) {

                }
            }
        }

        String mobile = "15229025928张磊";
        System.out.println("正则匹配"+ mobile.matches("^[0-9]\\d*$"));

//        if(rule.getCompareBegin()<1 || rule.getCompareEnd() > value.length()) {
//            continue;
//        }
//
//        String subStr = value.substring(rule.getCompareBegin()-1, rule.getCompareEnd()-1);
//        for (String s : matchContent) {
//            if(StringUtils.startsWithIgnoreCase(subStr, s)) {
//                return rule.getItemName() + result;
//            }
//        }

        String value = "一海淀";
        String subStr = value.substring(1,3);
        System.out.println(subStr);


//        System.out.println(set1.retainAll(set2));
    }

    private static void compute() {
        sysNumber();
        Date today = new Date();
        Date yesterday = new Date(getCurTimeMillis() - 86400000L);
        System.out.println(today.toString() + "______" + yesterday.toString());

        String today1 = "2021-01-29 23:59:59";
        try {
            System.out.println(DateUtil.getNextDayEndTime(today1, 3));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        float num = 5380L;
        float total = 0L;
        for (int i = 0; i < 19; i++) {
            total = (float) (total + num * Math.pow(lilv, 20-i));
        }
        System.out.println(total);

    }

    private static float tsetOne() {
        float num = 11784;
        float total = 0L;
//        float n = (float) 1.05;
        for (int i = 0; i < 10; i++) {
            double theYear = num * Math.pow(lilv, 32-i);
            total = (float) (total + theYear);
            System.out.println("第"+(i+1)+"年存的"+num+","+(32-i)+"年，本息和："+theYear);
        }
        System.out.println("共交"+num*10);
        System.out.println(total);
        return total;
    }

    private static void testLocalDate() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(format.format(date));
        LocalDate localDate = LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault());
        System.out.println(localDate.toString());
        for (int i = 0; i < 30; i++) {
            System.out.println(localDate.plusDays(i));
        }
    }

    private  static String genereteNumber() {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate=sdf.format(new Date());
        Random random=new Random();
        String result= random.nextInt(999)+"";
        //随机三次保证编号长度后面都是加3个随机数
        if (result.length()<3) {
            System.out.printf(result.length()+"_");
            System.out.printf(result);
        }
        result = result.length() == 3? result: (result.length()==2? "0"+result : "00"+result);
        System.out.println(result);


        return newDate+result;
    }


    private static String replaceMobile(String mobile) {
        return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    private static String replaceEmail(String email) {
        return email.replaceAll("(\\w+)\\w{3}@(\\w+)", "$1***@$2");
    }

    public static String markEmail(String email) {
        if (email!=null && !email.equals("")) {
            String[] emailArr = email.split("@");
            return emailArr[0].length() < 3 ? emailArr[0] + "***@" + emailArr[1] : emailArr[0].substring(0, 2) + "***@" + emailArr[1];
        } else {
            return "";
        }
    }

    public int allCells(int n) {
        return aCells(n) + bCells(n) + cCells(n);
    }

    private int cCells(int n) {
        if(n<=1) {
            return 0;
        }
        return bCells(n-1);
    }

    private int bCells(int n) {
        if(n==1) {
            return 1;
        }
        if(n==0) {
            return 0;
        }
        return aCells(n-1);
    }

    private int aCells(int n) {
        if(n==0) {
            return 1;
        }
        return allCells(n-1);
    }

    public static int dispatchCandy(int[] candy, int[] glist) {
        int match = 0;
        //糖果从大到小排序
        Arrays.sort(candy);
        //孩子期望从大到小排序
        Arrays.sort(glist);

        int index2 = 0;

        for (int i = 0; i < glist.length; i++) {
            for (int j = index2; j < candy.length; j++) {
                if(glist[i]<=candy[j]) {
                    match += 1;
                    index2 += 1;
                    break;
                }
            }
        }
        System.out.println(match);
        //这道题的根本是，放弃那些 胃口太大的孩子& 糖满足不了任何人的糖
        return  0;
    }

    /**
     * 移除最小区间
     */
    public  static void sysNumber() {
        long minId = 1;
        long maxId = 10;
        int batch = 3;
        while (minId<maxId) {
            System.out.println("查询【"+minId+"】,"+batch+"行");
            minId += batch;
        }
    }
}
